package lang;

import model.code.line.Line;
import model.symbol.DataType;
import util.ByteList;

import java.util.ArrayList;

/**
 * This is the superclass of all language parsing classes.
 *
 * @author Neil Dickson
 */
public abstract class Parser {
	/**
	 * Resolves the references on the {@link model.code.line.Line} of text
	 * @param line			the {@link model.code.line.Line} to parse
	 */
	public abstract void tokenizeLine(Line line);

	/**
	 * Performs Dijkstra's shunting algorithm on an immediate expression.
	 * @param line			the line containing the immediate expression to be evaluated
	 * @param startIndex	the starting token index (inclusive) of the immediate
	 * @param endIndex		the ending token index (exclusive) of the immediate
	 * @return an Immediate if the value is valid, null if there is an unknown token,
	 *         or {@link model.code.line.SyntaxError} if there is an error in the syntax
	 */
	public abstract Object immediateShunting(Line line,int startIndex,int endIndex);

	/**
	 * Evaluates the text representation of an array, structure, or array of structures
	 * @param line			the line containing the text to be evaluated
	 * @param type			the data type of the elements of the array or the {@link model.code.Structure}
	 * @param bytes			the list of bytes to be filled with the value of this array, or null if only the size is desired
	 * @param relocations	the list of relocations to be filled with any relocation entries in the value of this array, or null if only the size is desired
	 * @param startIndex	the starting token index (inclusive) of the immediate
	 * @param endIndex		the ending token index (exclusive) of the immediate
	 * @return an Integer with the length in bytes if the value is valid, null if there is an unknown token,
	 *         or {@link model.code.line.SyntaxError} if there is any syntax error listed for the line
	 */
	public abstract Object evaluateArray(Line line, DataType type, ByteList bytes, ArrayList<Encoder.Relocation> relocations, int startIndex, int endIndex);
}